package thread;

public class ThreadDemo1 extends Thread{
    public static void main(String[] args) {
        MyThread th1=new MyThread();
        MyThread th2=new MyThread();
//        start方法开启线程，会自动调用run方法
        th1.start();
        th2.start();
//        th.run();没有开启线程
//        th1.run();
        MyThread2 th3=new MyThread2();
        th3.start();
        for(int i=1;i<=500000;i++){
            new Demo();
        }
    }

}

class MyThread extends Thread{
    @Override
    public void run(){
    for(int i=1;i<=200;i++){
        System.out.println("线程任务执行了"+i);
    }
    }
}
class MyThread2 extends Thread{
    int[] arr={12,1,2,2,2,2,2,22,2,22,111,1,1};
    @Override
    public void run(){

        for (int i : arr) {
            System.out.println(i);
        }

    }
}

class Demo{
    @Override
    protected void finalize() throws Throwable{
        System.out.println("垃圾被清理了");
    }
}